
<?php

/**
 * Created by PhpStorm.
 * User: qiliping
 * Date: 2016/12/7
 * Time: 上午10:52
 */
class Offline_Course_Order extends CI_Model
{
	/**
	**  查询自己的订单
	*/
	public function get_offline_order_list_by_user($limit = 0, $offset = 10, $user_id,$status=-1,$order_num=0,$begin_time=0,$end_time=0)
	{
		$where = " ord.buyer_user_id = '{$user_id}' ";

		$where .= " AND ord.order_type = 3 ";
		if($status>-1)
		{
		  $where .= " AND ord.order_status = $status ";
		}
		if(!empty($begin_time))
		{
			$begin_time=strtotime($begin_time);
			$where .= " AND ord.order_time >= {$begin_time} ";
		}
		
		if(!empty($end_time))
		{
			$end_time=strtotime($end_time) + 3600 * 24;
			$where .= " AND ord.order_time <= {$end_time} ";
		}
		if(!empty($order_num))
		{
			$where .= " AND ord.order_num like '%".$order_num."%'";
		}
		$this->db->trans_start();
		$sql = "SELECT SQL_CALC_FOUND_ROWS ord.*,cam.name as campus_name,stu.student_id,stu.name as student_name FROM {$this->db->dbprefix}shopping_orders ord left join {$this->db->dbprefix}o2o_school_campus cam on cam.id = ord.school_campus_id left join {$this->db->dbprefix}o2o_student stu on stu.user_id = ord.buyer_user_id where $where LIMIT $limit, $offset;";

		$result = $this->db->query($sql)->result_array();
		$row_num =  $this->db->query('SELECT FOUND_ROWS() as row_num;')->row_array();

		$this->db->trans_complete();

		return array("total_count" => $row_num['row_num'], "result" => $result);
	}

	/**
	 * [get_order_item_by_order_id description]
	 * @param  [type] $order_id [description]
	 * @return [type]           [description]
	 */
	public function get_order_item_by_order_id($order_id)
	{
		$sql = "SELECT course_id,course_name FROM {$this->db->dbprefix}shopping_order_item WHERE order_id={$order_id}";
		return $this->db->query($sql)->result_array();
	}


}